#include<iostream>
#include<signal.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<sys/stat.h>
using namespace std;


void myhandler(int signo)
{
    cout<<"get a signal, num: "<<signo<<endl;
    pid_t rid;
    while((rid==waitpid(-1,NULL,0))>0)
    {
        cout<<"wait success!!,rid: "<<rid<<endl;
    }
    cout<<"child quit!!,pid: "<<getpid()<<endl;
}

int main()
{
    signal(SIGCHLD,myhandler);

    pid_t id=fork();
    if(id==0) //child
    {
        cout<<"I am a child,pid: "<<getpid()<<endl;
        sleep(1);
        exit(0);
    }
    //father
    while(true)
    {
        cout<<"I am a father,is runing...."<<endl;
        sleep(1);
    }
    return 0;
}